{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
<!--    <a href="{php echo createWebUrlPlugin('weike.index.main',array('themeid'=>$themeid));}" >-->
<!--        <button class="btn btn-primary" style="margin-bottom: 15px;">返回客片列表</button>-->
<!--    </a>-->
    {include file='../../plugin/weike/template/web/common_nav'}
    {if $wk_id > 0}
    <div class="panel panel-default" role="tabpanel" style="">
        <div class="panel-heading">链接</div>
        <div class="panel-body">
            <form id="url_from" class="form-horizontal" role="form">
                <div class="form-group" >
                    <label class="col-sm-2 col-xs-12 control-label">小程序码</label>
                    <div class="col-sm-2 col-xs-12">
                        <img src="{php echo tomedia($wk_url);}" style="width: 150px;height: 150px;padding: 1px;">
                    </div>
<!--                    <div class="col-sm-1 col-md-8 col-lg-4 col-xs-12" style="margin-top: 60px;">-->
<!--                        <a class="btn btn-warning btn-sm btn-sm" style="width: 35px"  data-type="delete" onclick="resetCode({$wk_id})"-->
<!--                           title="重置小程序码" data-toggle="tooltip" data-placement="top"><i class="fa fa-undo"> </i></a>-->
<!--                        <br>重置小程序码-->
<!--                    </div>-->
                </div>
                <div class="form-group" >
                    <label class="col-sm-2 col-xs-12 control-label">绑定状态：</label>
                    <div class="col-sm-9 col-md-8 col-lg-2 col-xs-12">
                        {if !empty($wkUserInfo) }
                        <span>{$wkUserInfo['nickname']}</span>
                        <img src="{$wkUserInfo['avatar']}" style="height: 60px;width: 60px;margin-left: 10px;">
                        {else}
                        <span>未绑定</span>
                        {/if}
                    </div>
                    {if !empty($wkUserInfo) }
                    <div class="col-sm-9 col-md-8 col-lg-4 col-xs-12" style="margin-top: 12px;">
                        <a class="btn btn-warning btn-sm btn-sm" style="width: 35px"  data-type="delete" onclick="removeBind({$wk_id})"
                           title="重置绑定" data-toggle="tooltip" data-placement="top"><i class="fa fa-undo"> </i></a>
                        <br>重新绑定
                    </div>
                    {/if}
                </div>
            </form>
        </div>
    </div>
    {/if}
    <form id="weike_form" action="" method="post" class="form-horizontal" role="form">
        <div class="panel panel-default" role="tabpanel" style="">
        <div class="panel-heading">照片设置</div>
        <div class="panel-body">
            <input type="hidden" name="wk_id" value="{$wk_id}"/>
            <input type="hidden" name="themeid" value="{$themeid}"/>
            <div class="form-group" >
                <label class="col-sm-2 col-xs-12 control-label">客户姓名</label>
                <div class="col-sm-8 col-xs-12">
                    <div class="input-group">
                        <input type="text" class="form-control"  placeholder="请输入姓名" name="name"  value="{php echo !$wk_id?'':$data['name'];}">
                        <span class="input-group-addon"></span>
                    </div>
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 col-xs-12 control-label">上传照片</label>
                <div class="col-sm-8 col-xs-12">
                    {php echo view_form_field_multi_image('photo',$wk_id?$wk_config['photo']:[]);}
                    <span class="help-block"></span>
                </div>
            </div>
            {if $wk_id > 0}
            <div class="form-group">
                <label class="col-sm-2 col-xs-12 control-label">分享图片</label>
                <div class="col-sm-8 col-xs-12">
                    {php echo view_form_field_image('share_img',$wk_config['shareimg']);}
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 col-xs-12 control-label">照片展示形式</label>
                <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                    <label class="radio-inline">
                        <input name="show_type" value="0" {if !$wk_id || !$wk_config['show_type']} checked="checked"{/if} type="radio">banner轮播+页面
                    </label>
                    <label class="radio-inline">
                        <input name="show_type" value="1" {if $wk_id && $wk_config['show_type']==1} checked="checked"{/if} type="radio">仅banner轮播
                    </label>
                    <label class="radio-inline">
                        <input name="show_type" value="2" {if $wk_id && $wk_config['show_type']==2} checked="checked"{/if} type="radio">仅页面
                    </label>
                </div>
            </div>
            {/if}
            <div class="form-group">
                <label class="col-sm-2 col-xs-12 control-label">选择员工</label>
                <div class="col-sm-8 col-xs-12">
                    <select class="form-control" name="workerid">
                        <option value="0" {if $workerid == 0 }selected="selected"{/if}>请选择员工</option>
                        {loop $wlist $row}
                        <option value="{$row['uid']}" {if $workerid == $row['uid'] }selected="selected"{/if}>{$row['teamname']}-{$row['username']}</option>
                        {/loop}
                    </select>
                </div>
            </div>
        </div>
    </div>
        {if $wk_id > 0}

        <div class="panel panel-default" role="tabpanel" style="">
            <div class="panel-heading">默认参数修改</div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">起止时间</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_daterange('call_time', array('start'=>$wk_config['start_time']?:'','end'=>$wk_config['end_time']?:''), false);}
                        <span class="help-block">选择活动起止时间</span>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">打call礼品</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        {if !empty($wk_call_gift_groups)}
                        <select class="form-control" name="wk_call_gift_group_id">
                            {loop $wk_call_gift_groups $index $item}
                            <option value="{php echo $item['id'];}" {php echo ($item['id'] == $wk_config['wk_call_gift_group_id'])?'selected':'';}>{$item['title']}</option>
                            {/loop}
                        </select>
                        {else}
                        <select class="form-control" name="wk_call_gift_group_id">
                            <option value="0" selected="selected">未选择，会使用默认打call礼品分组</option>
                        </select>
                        {/if}
                    </div>
                    <div class="col-sm-9 col-md-8 col-lg-2 col-xs-12">
                        <a href="{php echo createWebUrlPlugin('weike.call.main',array('themeid'=>$themeid));}" >
                            <div style="margin-top: 8px;color: #2c90e6;">
                                编辑礼品
                            </div>
                        </a>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">打赏礼物</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        {if !empty($wk_gift_groups)}
                        <select class="form-control" name="wk_gift_group_id">
                            {loop $wk_gift_groups $index $item}
                            <option value="{php echo $item['id'];}" {php echo ($item['id'] == $wk_config['wk_gift_group_id'])?'selected':'';}>{$item['title']}</option>
                            {/loop}
                        </select>
                        {else}
                        <select class="form-control" name="wk_gift_group_id">
                            <option value="0" selected="selected">未选择，会使用默认打赏礼物分组</option>
                        </select>
                        {/if}
                    </div>
                    <div class="col-sm-9 col-md-8 col-lg-2 col-xs-12">
                        <a href="{php echo createWebUrlPlugin('weike.gift.main',array('themeid'=>$themeid));}" >
                            <div style="margin-top: 8px;color: #2c90e6;">
                                编辑礼物
                            </div>
                        </a>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">选择音乐</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <select class="form-control" name="music_id" id="wk_music_id">
                            <option value="0" {if !$music_id }selected="selected"{/if}>请选择音乐</option>
                            {loop $music_list $row}
                            <option value="{$row['id']}" data-id="{$row['id']}" data-musicurl="{$row['url']}" {if $music_id === $row['id'] }selected="selected"{/if}>{$row['name']}</option>
                            {/loop}
                        </select>
                    </div>
                    <div class="col-sm-9 col-md-8 col-lg-2 col-xs-12">
                        <a href="{php echo createWebUrlPlugin('weike.music.main',array('themeid'=>$themeid));}" >
                            <div style="margin-top: 8px;color: #2c90e6;">
                                编辑音乐
                            </div>
                        </a>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label"></label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <input type="text" value="{$music_src}" name="music_src" class="form-control audio-player-media" autocomplete="off" id="wk_music_input">
                            <audio src="{$music_src}" id="wk_audio_self" style="display: none;"></audio>
                            <span class="input-group-btn">
                                <button class="btn btn-default audio-player-play" type="button" style="" onclick="audio_play()"><i class="fa fa-play" id="wk_music_icon"></i></button>
                            </span>
                        </div>
                        <span class="help-block"></span>
                    </div>
                </div>

            </div>
        </div>

        <div class="panel panel-default" role="tabpanel" style="">
            <div class="panel-heading">信息统计</div>
            <div class="panel-body">
                <div class="form-group" >
                    <div class="col-sm-9 col-xs-12 col-md-8 col-lg-6">
                        <label class="col-sm-4 col-xs-12 control-label">打call数</label>
                        <div class="col-sm-4 col-xs-12">
                            <input type="text" class="form-control" name="call_num"  value="{php echo $data['call_num'];}">
                        </div>
                    </div>
                    <div class="col-sm-9 col-xs-12 col-md-8 col-lg-6">
                        <div class="input-group">
                            <label class="col-sm-2 col-xs-12 control-label">礼物数</label>
                            <div class="col-sm-4 col-xs-12">
                                <input type="text" class="form-control" name="gift_num"  value="{php echo $data['gift_num'];}">
                            </div>
                            <label class="col-sm-2 col-xs-12 control-label">金币数</label>
                            <div class="col-sm-4 col-xs-12">
                                <input type="text" class="form-control" name="money"  value="{php echo $data['money'];}">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group" >
                    <div class="col-sm-9 col-xs-12 col-md-8 col-lg-6">
                        <div class="panel-body table-responsive">
                            <table class="table table-hover">
                                <thead class="navbar-inner">
                                <tr>
                                    <th style="">序号</th>
                                    <th style="">头像</th>
                                    <th style="">昵称</th>
                                    <th style="">打call时间</th>
                                </tr>
                                </thead>
                                <tbody>
                                {loop $call_list $index $item}
                                <tr>
                                    <td>{php echo $index+1;}</td>
                                    <td><img src="{$item['avatar']}" style="width: 30px;height: 30px;"></td>
                                    <td>{$item['nickname']}</td>
                                    <td>{$item['created_at']}</td>
                                </tr>
                                {/loop}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="col-sm-9 col-xs-12 col-md-8 col-lg-6">
                        <div class="panel-body table-responsive">
                            <table class="table table-hover">
                                <thead class="navbar-inner">
                                <tr>
                                    <th style="">序号</th>
                                    <th style="">头像</th>
                                    <th style="">昵称</th>
                                    <th style="">礼物数</th>
                                    <th style="">金币</th>
                                    <th style="">时间</th>
                                </tr>
                                </thead>
                                <tbody>
                                {loop $gift_list $index $item}
                                <tr>
                                    <td>{php echo $index+1;}</td>
                                    <td><img src="{$item['avatar']}" style="width: 30px;height: 30px;"></td>
                                    <td>{$item['nickname']}</td>
                                    <td>1</td>
                                    <td>{$item['price']}</td>
                                    <td>{$item['created_at']}</td>
                                </tr>
                                {/loop}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="form-group" >
                    <div class="col-sm-9 col-xs-12 col-md-8 col-lg-6">
                        <label class="col-sm-6 col-xs-12 control-label">
                            <a href="{php echo createWebUrlPlugin('weike.call.listinfo',array('themeid'=>$themeid,'wk_id'=>$wk_id));}" title="查看更多"><span class="label label-warning">查看更多</span></a>
                        </label>
                    </div>
                    <div class="col-sm-9 col-xs-12 col-md-8 col-lg-6">
                        <label class="col-sm-6 col-xs-12 control-label">
                            <a href="{php echo createWebUrlPlugin('weike.gift.listinfo',array('themeid'=>$themeid,'wk_id'=>$wk_id));}" title="查看更多"><span class="label label-warning">查看更多</span></a>
                        </label>
                    </div>
                </div>
            </div>
        </div>
        {/if}
        <div class="form-group" id="sub_upload" >
            <div class="col-sm-12">
                <input name="submit" onclick="addOrEditItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
            </div>
        </div>
    </form>
</div>


{$pager}
<script type="text/javascript">
    $(document).ready(
        function (){
            console.log('js代码');
        }
    );
    // $(function(){
    //     $('#weike_form').submit(function(){
    //
    //     });
    // });
    //新增\修改 提交数据
    function addOrEditItem() {
        let postUrl = "{php echo createWebUrlPlugin('weike.index.addinfo',array('themeid'=>$themeid));}";
        let formData = $("#weike_form").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                console.log(e)
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.message)
                }else{
                    layer.msg(result.message);
                    let success_redirect = "{php echo createWebUrlPlugin('weike.index.addpage',array('themeid'=>$themeid,'wk_id'=>$item['id']));}"+"&wk_id="+result.wk_id;
                    window.location.href = success_redirect;
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    function removeBind(id) {
        layer.confirm('确定进行解绑操作？',{
            btn:['确定']
        },function () {
            let postUrl = "{php echo createWebUrlPlugin('weike.index.removeBind',array('themeid'=>$themeid));}";
            let success_redirect = "{php echo createWebUrlPlugin('weike.index.addpage',array('themeid'=>$themeid,'wk_id'=>$wk_id));}";
            $.ajax({
                url:postUrl,
                dataType:'json',
                method:'post',
                data:{'wk_id':id},
                success:function (e) {
                    let status = e.status;
                    let result = e.result;
                    if (status!=1){
                        layer.msg(result.message)
                    }else{
                        layer.msg(result.message);
                        window.location.href = success_redirect;
                    }
                },
                fail:function (err) {
                    console.log(err)
                }
            })
        })
    }
    function resetCode(id) {
        layer.confirm('确定重置小程序码？',{
            btn:['确定']
        },function () {
            let postUrl = "{php echo createWebUrlPlugin('weike.index.resetCode',array('themeid'=>$themeid));}";
            let success_redirect = "{php echo createWebUrlPlugin('weike.index.addpage',array('themeid'=>$themeid,'wk_id'=>$wk_id));}";
            $.ajax({
                url:postUrl,
                dataType:'json',
                method:'post',
                data:{'wk_id':id},
                success:function (e) {
                    let status = e.status;
                    let result = e.result;
                    if (status!=1){
                        layer.msg(result.message)
                    }else{
                        layer.msg(result.message);
                        window.location.href = success_redirect;
                    }
                },
                fail:function (err) {
                    console.log(err)
                }
            })
        })
    }
    function audio_play() {
        var videosr = $('#wk_audio_self');
        if(!$('#wk_music_input').val()) return;
        if($('#wk_music_icon').hasClass('fa-stop')){
            videosr[0].pause();
            $("#wk_music_icon").addClass('fa-play');
            $("#wk_music_icon").removeClass("fa-stop");
        }else {
            videosr[0].play();
            $("#wk_music_icon").addClass("fa-stop");
            $("#wk_music_icon").removeClass('fa-play');
        }

    }
    $("#wk_music_id").change(function () {
        let tmp_music_id = $(this).val();
        let tmp_music_src = '';
        $(this).find('option').each((index, item) => {
            if($(item).data('id') == tmp_music_id) {
                tmp_music_src = $(item).data('musicurl');
            }
        });
        $('#wk_audio_self').attr('src',tmp_music_src);
        $('#wk_music_input').val(tmp_music_src);
    })
</script>
